/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.grafico;

import br.ufc.quixada.adrs.model.QuestionarioQualitativo;
import br.ufc.quixada.adrs.model.RelatorioQualitativoResult;
import java.util.Date;
import java.util.List;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.XYBarDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author jefferson
 */
public class DataSetFactory {

    public static Double modaPercentquestoesPos;
    public static Double mediaPercentquestoesPos;

    public static CategoryDataset criarBarDataset() {

        // create the dataset...
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int counter = 1;
        for (int i = 0; i < 10; i++) {
            dataset.addValue(13 + counter, "" + "Respostas", "Q " + counter + ")");
            counter++;
        }
        return dataset;

    }

    public static IntervalXYDataset createXYDataset() {
        XYSeries series = new XYSeries("Resposta dos adrs");
        XYSeries series2 = new XYSeries("Series 2");
        XYSeries series3 = new XYSeries("Series 3");

        series.add(1.0, 5.0);
        series2.add(2.0, 70.8);
        series3.add(3.0, 48.3);

        series.add(4.0, 2.0);
        series2.add(5.0, 70.8);
        series3.add(6.0, 48.3);
        series.add(7.0, 4.0);
        series2.add(14.0, 70.8);
        series3.add(8.0, 48.3);
        series.add(9.0, 7.0);
        series2.add(10.0, 70.8);
        series3.add(11.0, 48.3);
        series.add(12.0, 3.0);
        series2.add(13.0, 70.8);
        series3.add(15, 48.3);

        XYSeriesCollection collection = new XYSeriesCollection();
        collection.addSeries(series);
        collection.addSeries(series2);
        collection.addSeries(series3);

        return new XYBarDataset(collection, 0.9);
    }

    public static CategoryDataset createStackedBarDataset() {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(10.0, "Series 1", "C1");
        dataset.addValue(5.0, "Series 1", "C2");
        dataset.addValue(6.0, "Series 1", "C3");
        dataset.addValue(7.0, "Series 1", "C4");
        dataset.addValue(8.0, "Series 1", "C5");
        dataset.addValue(9.0, "Series 1", "C6");
        dataset.addValue(10.0, "Series 1", "C7");
        dataset.addValue(11.0, "Series 1", "C8");
        dataset.addValue(3.0, "Series 1", "C9");

        dataset.addValue(4.0, "Series 2", "C1");
        dataset.addValue(7.0, "Series 2", "C2");
        dataset.addValue(17.0, "Series 2", "C3");
        dataset.addValue(15.0, "Series 2", "C4");
        dataset.addValue(6.0, "Series 2", "C5");
        dataset.addValue(8.0, "Series 2", "C6");
        dataset.addValue(9.0, "Series 2", "C7");
        dataset.addValue(13.0, "Series 2", "C8");
        dataset.addValue(7.0, "Series 2", "C9");

        dataset.addValue(15.0, "Series 3", "C1");
        dataset.addValue(14.0, "Series 3", "C2");
        dataset.addValue(12.0, "Series 3", "C3");
        dataset.addValue(11.0, "Series 3", "C4");
        dataset.addValue(10.0, "Series 3", "C5");
        dataset.addValue(0.0, "Series 3", "C6");
        dataset.addValue(7.0, "Series 3", "C7");
        dataset.addValue(9.0, "Series 3", "C8");
        dataset.addValue(11.0, "Series 3", "C9");

        dataset.addValue(14.0, "Series 4", "C1");
        dataset.addValue(3.0, "Series 4", "C2");
        dataset.addValue(7.0, "Series 4", "C3");
        dataset.addValue(0.0, "Series 4", "C4");
        dataset.addValue(9.0, "Series 4", "C5");
        dataset.addValue(6.0, "Series 4", "C6");
        dataset.addValue(7.0, "Series 4", "C7");
        dataset.addValue(9.0, "Series 4", "C8");
        dataset.addValue(10.0, "Series 4", "C9");

        return dataset;

    }

    public static CategoryDataset createADRSBarChartDataset() {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        String seriesKey = "doencas";
        dataset.addValue(1, seriesKey, "Brucelose");
        dataset.addValue(2, seriesKey, "Aftosa");
        dataset.addValue(3, seriesKey, "Carrapato");
        dataset.addValue(4, seriesKey, "Mulestia");
        dataset.addValue(5, seriesKey, "ferida");
        dataset.addValue(6, seriesKey, "Calo");
        dataset.addValue(7, seriesKey, "Bolha");
        dataset.addValue(8, seriesKey, "Furunculo");
        dataset.addValue(9, seriesKey, "Pereba");
        dataset.addValue(10, seriesKey, "Dores");
        dataset.addValue(11, seriesKey, "Vomito");
        dataset.addValue(12, seriesKey, "Diarreia");
        dataset.addValue(10, seriesKey, "Brucelose2");
        dataset.addValue(10, seriesKey, "Aftosa2");
        dataset.addValue(12, seriesKey, "Carrapato2");
        dataset.addValue(20, seriesKey, "Mulestia2");
        dataset.addValue(12, seriesKey, "ferida2");
        dataset.addValue(20, seriesKey, "Calo2");
        dataset.addValue(13, seriesKey, "Bolha2");
        dataset.addValue(14, seriesKey, "Furunculo2");
        dataset.addValue(17, seriesKey, "Pereba2");
        dataset.addValue(18, seriesKey, "Dores2");
        dataset.addValue(9, seriesKey, "Vomito2");
        dataset.addValue(9, seriesKey, "Diarreia2");
        dataset.addValue(10, seriesKey, "Brucelose3");
        dataset.addValue(10, seriesKey, "Aftosa3");
        dataset.addValue(12, seriesKey, "Carrapato3");
        dataset.addValue(20, seriesKey, "Mulestia3");
        dataset.addValue(12, seriesKey, "ferida3");
        dataset.addValue(20, seriesKey, "Calo3");
        dataset.addValue(13, seriesKey, "Bolha3");
        dataset.addValue(14, seriesKey, "Furunculo3");
        dataset.addValue(17, seriesKey, "Pereba3");
        dataset.addValue(18, seriesKey, "Dores3");
        dataset.addValue(9, seriesKey, "Vomito3");
        dataset.addValue(9, seriesKey, "Diarreia3");
        dataset.addValue(10, seriesKey, "Brucelose4");
        dataset.addValue(10, seriesKey, "Aftosa4");
        dataset.addValue(12, seriesKey, "Carrapato4");
        dataset.addValue(20, seriesKey, "Mulesti4");
        dataset.addValue(12, seriesKey, "ferida4");
        dataset.addValue(20, seriesKey, "Calo4");
        dataset.addValue(13, seriesKey, "Bolha4");
        dataset.addValue(14, seriesKey, "Furunculo4");
        dataset.addValue(17, seriesKey, "Pereba4");
        dataset.addValue(18, seriesKey, "Dores4");
        dataset.addValue(9, seriesKey, "Vomito4");
        dataset.addValue(9, seriesKey, "Diarreia4");
        dataset.addValue(10, seriesKey, "Brucelose5");
        dataset.addValue(10, seriesKey, "Aftosa5");
        dataset.addValue(12, seriesKey, "Carrapato5");
        dataset.addValue(20, seriesKey, "Mulesti5");
        dataset.addValue(12, seriesKey, "ferida5");
        dataset.addValue(20, seriesKey, "Calo5");
        dataset.addValue(13, seriesKey, "Bolha5");
        dataset.addValue(14, seriesKey, "Furunculo5");
        dataset.addValue(17, seriesKey, "Pereba5");
        dataset.addValue(18, seriesKey, "Dores5");
        dataset.addValue(9, seriesKey, "Vomito5");
        dataset.addValue(9, seriesKey, "Diarreia5");

        dataset.addValue(1, seriesKey, "Brucelose0");
        dataset.addValue(2, seriesKey, "Aftosa0");
        dataset.addValue(3, seriesKey, "Carrapato0");
        dataset.addValue(4, seriesKey, "Mulestia0");
        dataset.addValue(5, seriesKey, "ferida0");
        dataset.addValue(6, seriesKey, "Calo0");
        dataset.addValue(7, seriesKey, "Bolha0");
        dataset.addValue(8, seriesKey, "Furunculo0");
        dataset.addValue(9, seriesKey, "Pereba0");
        dataset.addValue(10, seriesKey, "Dores0");
        dataset.addValue(11, seriesKey, "Vomito0");
        dataset.addValue(12, seriesKey, "Diarreia0");
        dataset.addValue(10, seriesKey, "Brucelose20");
        dataset.addValue(10, seriesKey, "Aftosa20");
        dataset.addValue(12, seriesKey, "Carrapato20");
        dataset.addValue(20, seriesKey, "Mulestia20");
        dataset.addValue(12, seriesKey, "ferida20");
        dataset.addValue(20, seriesKey, "Calo20");
        dataset.addValue(13, seriesKey, "Bolha20");
        dataset.addValue(14, seriesKey, "Furunculo20");
        dataset.addValue(17, seriesKey, "Pereba20");
        dataset.addValue(18, seriesKey, "Dores20");
        dataset.addValue(9, seriesKey, "Vomito20");
        dataset.addValue(9, seriesKey, "Diarreia20");
        dataset.addValue(10, seriesKey, "Brucelose30");
        dataset.addValue(10, seriesKey, "Aftosa30");
        dataset.addValue(12, seriesKey, "Carrapato30");
        dataset.addValue(20, seriesKey, "Mulestia30");
        dataset.addValue(12, seriesKey, "ferida30");
        dataset.addValue(20, seriesKey, "Calo30");
        dataset.addValue(13, seriesKey, "Bolha30");
        dataset.addValue(14, seriesKey, "Furunculo30");
        dataset.addValue(17, seriesKey, "Pereba30");
        dataset.addValue(18, seriesKey, "Dores30");
        dataset.addValue(9, seriesKey, "Vomito30");
        dataset.addValue(9, seriesKey, "Diarreia30");
        dataset.addValue(10, seriesKey, "Brucelose40");
        dataset.addValue(10, seriesKey, "Aftosa40");
        dataset.addValue(12, seriesKey, "Carrapato40");
        dataset.addValue(20, seriesKey, "Mulesti40");
        dataset.addValue(12, seriesKey, "ferida40");
        dataset.addValue(20, seriesKey, "Calo40");
        dataset.addValue(13, seriesKey, "Bolha40");
        dataset.addValue(14, seriesKey, "Furunculo40");
        dataset.addValue(17, seriesKey, "Pereba40");
        dataset.addValue(18, seriesKey, "Dores40");
        dataset.addValue(9, seriesKey, "Vomito40");
        dataset.addValue(9, seriesKey, "Diarreia40");
        dataset.addValue(10, seriesKey, "Brucelose50");
        dataset.addValue(10, seriesKey, "Aftosa50");
        dataset.addValue(12, seriesKey, "Carrapato50");
        dataset.addValue(20, seriesKey, "Mulesti50");
        dataset.addValue(12, seriesKey, "ferida50");
        dataset.addValue(20, seriesKey, "Calo50");
        dataset.addValue(13, seriesKey, "Bolha50");
        dataset.addValue(14, seriesKey, "Furunculo50");
        dataset.addValue(17, seriesKey, "Pereba50");
        dataset.addValue(18, seriesKey, "Dores50");
        dataset.addValue(9, seriesKey, "Vomito50");
        dataset.addValue(9, seriesKey, "Diarreia50");

        dataset.addValue(1, seriesKey, "Brucelose01");
        dataset.addValue(2, seriesKey, "Aftosa01");
        dataset.addValue(3, seriesKey, "Carrapato01");
        dataset.addValue(4, seriesKey, "Mulestia01");
        dataset.addValue(5, seriesKey, "ferida01");
        dataset.addValue(6, seriesKey, "Calo01");
        dataset.addValue(7, seriesKey, "Bolha01");
        dataset.addValue(8, seriesKey, "Furunculo01");
        dataset.addValue(9, seriesKey, "Pereba01");
        dataset.addValue(10, seriesKey, "Dores01");
        dataset.addValue(11, seriesKey, "Vomito01");
        dataset.addValue(12, seriesKey, "Diarreia01");
        dataset.addValue(10, seriesKey, "Brucelose201");
        dataset.addValue(10, seriesKey, "Aftosa20");
        dataset.addValue(12, seriesKey, "Carrapato201");
        dataset.addValue(20, seriesKey, "Mulestia201");
        dataset.addValue(12, seriesKey, "ferida201");
        dataset.addValue(20, seriesKey, "Calo201");
        dataset.addValue(13, seriesKey, "Bolha201");
        dataset.addValue(14, seriesKey, "Furunculo201");
        dataset.addValue(17, seriesKey, "Pereba201");
        dataset.addValue(18, seriesKey, "Dores201");
        dataset.addValue(9, seriesKey, "Vomito201");
        dataset.addValue(9, seriesKey, "Diarreia201");
        dataset.addValue(10, seriesKey, "Brucelose301");
        dataset.addValue(10, seriesKey, "Aftosa301");
        dataset.addValue(12, seriesKey, "Carrapato301");
        dataset.addValue(20, seriesKey, "Mulestia301");
        dataset.addValue(12, seriesKey, "ferida301");
        dataset.addValue(20, seriesKey, "Calo301");
        dataset.addValue(13, seriesKey, "Bolha301");
        dataset.addValue(14, seriesKey, "Furunculo301");
        dataset.addValue(17, seriesKey, "Pereba301");
        dataset.addValue(18, seriesKey, "Dores301");
        dataset.addValue(9, seriesKey, "Vomito301");
        dataset.addValue(9, seriesKey, "Diarreia301");
        dataset.addValue(10, seriesKey, "Brucelose401");
        dataset.addValue(10, seriesKey, "Aftosa401");
        dataset.addValue(12, seriesKey, "Carrapato401");
        dataset.addValue(20, seriesKey, "Mulesti401");
        dataset.addValue(12, seriesKey, "ferida401");
        dataset.addValue(20, seriesKey, "Calo401");
        dataset.addValue(13, seriesKey, "Bolha401");
        dataset.addValue(14, seriesKey, "Furunculo401");
        dataset.addValue(17, seriesKey, "Pereba401");
        dataset.addValue(18, seriesKey, "Dores401");
        dataset.addValue(9, seriesKey, "Vomito401");
        dataset.addValue(9, seriesKey, "Diarreia401");
        dataset.addValue(10, seriesKey, "Brucelose501");
        dataset.addValue(10, seriesKey, "Aftosa501");
        dataset.addValue(12, seriesKey, "Carrapato501");
        dataset.addValue(20, seriesKey, "Mulesti501");
        dataset.addValue(12, seriesKey, "ferida501");
        dataset.addValue(20, seriesKey, "Calo501");
        dataset.addValue(13, seriesKey, "Bolha501");
        dataset.addValue(14, seriesKey, "Furunculo501");
        dataset.addValue(17, seriesKey, "Pereba501");
        dataset.addValue(18, seriesKey, "Dores501");
        dataset.addValue(9, seriesKey, "Vomito501");
        dataset.addValue(9, seriesKey, "Diarreia501");
        return dataset;
    }

    public static CategoryDataset createADRSBarChartDataset(List<String> nomes, List<Integer> valores, String periodo) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < nomes.size(); i++) {
            Number number = valores.get(i);
            String serie = nomes.get(i);
            dataset.addValue(number, serie, periodo);
        }
        return dataset;
    }

    public static CategoryDataset createADRSBarChartDatasetQT(List<String> nomes, List<Integer> valores, List<Date> datas) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < nomes.size(); i++) {
            Number valor = valores.get(i);
            Comparable label = String.format("%1$Tb/%1$ty", datas.get(i));
            //String label = UtilAdrs.treatToMonthYearString(datas[i]);
            dataset.addValue(valor, nomes.get(i), label);
        }
        return dataset;
    }

    public static CategoryDataset createADRSBarChartDatasetQS(String[] nomes, int[] valores) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < valores.length; i++) {
            Number valor = valores[i];
            Comparable label = nomes[i];
            //String label = UtilAdrs.treatToMonthYearString(datas[i]);
            dataset.addValue(valor, "doencas", label);
        }
        return dataset;
    }

    public static CategoryDataset createADRSBarChartDatasetQTDescarte(List<String> nomes, List<Integer> valores) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < valores.size(); i++) {
            Number valor = valores.get(i);
            Comparable label = nomes.get(i);
            //String label = UtilAdrs.treatToMonthYearString(datas[i]);
            dataset.addValue(valor, "descartes", label);
        }
        return dataset;
    }

    public static DefaultCategoryDataset createDatasetTecnologico(List<RelatorioQualitativoResult> relatorio) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        QuestionarioQualitativo ql = new QuestionarioQualitativo();
        for (RelatorioQualitativoResult rel : relatorio) {
            String nQuestao = ql.getQuestaoByCodigo(rel.getQuestao());
            dataset.addValue(rel.getQuantidadesRespostas().get(RelatorioQualitativoResult.VALOR_RESPOSTA_NAO_RESPONDIDO), RelatorioQualitativoResult.RESPOSTA_NAO_RESPONDIDO, nQuestao);
            dataset.addValue(rel.getQuantidadesRespostas().get(RelatorioQualitativoResult.VALOR_RESPOSTA_NAO), RelatorioQualitativoResult.RESPOSTA_NAO, nQuestao);
            dataset.addValue(rel.getQuantidadesRespostas().get(RelatorioQualitativoResult.VALOR_RESPOSTA_SIM), RelatorioQualitativoResult.RESPOSTA_SIM, nQuestao);
            dataset.addValue(rel.getQuantidadesRespostas().get(RelatorioQualitativoResult.VALOR_RESPOSTA_SIM_ADEQUADAMENTE), RelatorioQualitativoResult.RESPOSTA_SIM_ADEQUADAMENTE, nQuestao);
        }
        return dataset;
    }

    public static DefaultCategoryDataset createDatasetQLTipoResposta(List<RelatorioQualitativoResult> relatorio, String tipoResposta, Integer resposta) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        QuestionarioQualitativo ql = new QuestionarioQualitativo();
        for (RelatorioQualitativoResult rel : relatorio) {
            String nQuestao = ql.getQuestaoByCodigo(rel.getQuestao());
            dataset.addValue(rel.getQuantidadesRespostas().get(resposta), tipoResposta, nQuestao);
        }
        return dataset;
    }

    public static DefaultCategoryDataset createDatasetQLPorcentagemTipoResposta(List<RelatorioQualitativoResult> relatorio, String tipoResposta, Integer resposta) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        QuestionarioQualitativo ql = new QuestionarioQualitativo();
        for (RelatorioQualitativoResult rel : relatorio) {
            String nQuestao = ql.getQuestaoByCodigo(rel.getQuestao());
            dataset.addValue(rel.getPorcentagemRespostas().get(resposta), tipoResposta, nQuestao);
        }
        return dataset;
    }
}
